function HandleDialogProduceNote(gui, item, options) {
  this._gui = gui;
  this._item = item;
  this._options = options;
  this._popupBox = new PopupBox();
  
  
  this._author = (options && options.author) ? options.author : null;
  this._now = (options && options.now) ? options.now : null;
  this._popupBox2 = (options && options.popupBox) ? options.popupBox : null;
  this._callbackFunc = (options && options.callbackFunc) ? options.callbackFunc : null;
  
  this._createElements();
};

HandleDialogProduceNote.prototype._createElements = function() {
  var _self = this;
  DOMUtils.removeTableRows(this._gui.mains, 1);
  
  MiscUtils.sort(this._item.v2_notes, ['content']);
  
  if (this._item.v2_notes.length == 0) {
    tr = this._gui.mains.insertRow(-1);
    td = tr.insertCell(-1);
    td.colSpan = 4;
    td.style.height = '24px';
    td.style.textAlign = 'center';
    td.style.borderRight = 'solid 1px #b4b4b4';
    td.style.borderBottom = 'solid 1px #b4b4b4';
    td.appendChild(document.createTextNode('N/A'));
  }
  
  for (var i = 0, il = this._item.v2_notes.length; i < il; i++) {
    var item = this._item.v2_notes[i];
    tr = this._gui.mains.insertRow(-1);
    
    td = tr.insertCell(-1);
    if (item.cancelled == 1) {
      td.style.textDecoration = 'line-through';
    }
    td.style.height = '24px';
    td.style.textAlign = 'center';
    td.style.borderRight = 'solid 1px #b4b4b4';
    td.style.borderBottom = 'solid 1px #b4b4b4';
    td.appendChild(document.createTextNode(SimpleDate.format(item.date)));
    
    td = tr.insertCell(-1);
    if (item.cancelled == 1) {
      td.style.textDecoration = 'line-through';
    }
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 15px';
    td.style.borderRight = 'solid 1px #b4b4b4';
    td.style.borderBottom = 'solid 1px #b4b4b4';
    td.appendChild(document.createTextNode(item.author));
    
    td = tr.insertCell(-1);
    if (item.cancelled == 1) {
      td.style.textDecoration = 'line-through';
    }
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 15px';
    td.style.borderRight = 'solid 1px #b4b4b4';
    td.style.borderBottom = 'solid 1px #b4b4b4';
    if (item.content.length != 0) {
      td.appendChild(document.createTextNode(item.content));
    } else {
      td.appendChild(document.createTextNode('(none)'));
    }
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.style.borderRight = 'solid 1px #b4b4b4';
    td.style.borderBottom = 'solid 1px #b4b4b4';
    var remove = document.createElement('img');
    remove.src = 'images/common/delete.png';
    remove.style.cursor = 'pointer';
    remove._object = item;
    remove.onclick = function() { this._object.cancelled = 1;
                                  var pos = DOMUtils.findPos(this);
                                  new RequestUtils()._write('producenote', [this._object], [], function() { _self._createElements(); }, { php: Constant.FACTORY + '/customphp/mysqlwrite.php', pos: pos });
                                };
    if (item.cancelled == 0 && this._item.cancelled == 0) {
      td.appendChild(remove);
    }
  }
  
  this._gui.input.disabled = false;
  if (this._item.cancelled == 1) {
    this._gui.input.disabled = true;
    this._gui.add.style.display = 'none';
  }
  
  this._note = ProduceNote.instance();
  this._gui.input.value = this._note.content;
  this._gui.input.onchange = function() { _self._note.content = this.value; };
  
  this._gui.add.onclick = function() { if (_self._note.content == '') {
                                         window.alert('CAN NOT BE EMPTY');
                                         return;
                                       }
                                       _self._note.author = _self._author.account;
                                       _self._note.date = _self._now;
                                       _self._note.produce_trackId = _self._item.trackId;
                                       new RequestUtils()._write('producenote', [_self._note], [], function() { _self._loadData(); }, { php: Constant.FACTORY + '/customphp/mysqlwrite.php', pos: DOMUtils.findPos(this) });
                                     };
  this._gui.close.onclick = function() { _self._popupBox2._close(); _self._callbackFunc(); };
};

HandleDialogProduceNote.prototype._loadData = function() {
  var _self = this;
  DOMUtils.removeTableRows(this._gui.mains, 1);
  
  tr = this._gui.mains.insertRow(-1);
  td = tr.insertCell(-1);
  td.colSpan = 4;
  td.style.textAlign = 'center';
  td.appendChild(DOMUtils.getLoadingImage());

  this._retrieveProduce();
};

HandleDialogProduceNote.prototype._retrieveProduce = function() {
  var _self = this;
  var args = '&c=n.produce_trackId = \'' + this._item.trackId + '\'';
  new RequestUtils()._mysql('producenote', args, function(result, params) { _self._item.v2_notes = result.data;
                                                                            _self._createElements.call(_self);
                                                                          }, { php: Constant.FACTORY + '/customphp/mysqlcustom.php' });
};
